package top.tagao.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.tagao.yygh.common.result.Result;
import top.tagao.yygh.model.user.UserInfo;
import top.tagao.yygh.user.service.UserInfoService;
import top.tagao.yygh.vo.user.UserInfoQueryVo;

import java.util.Map;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/12 21:08
 */
@Api(tags = "后台用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;


    @ApiOperation(value = "用户锁定 0:锁定 1:正常")
    @GetMapping("lock/{id}/{status}")
    public Result lock(@PathVariable Long  id, @PathVariable Integer status){
        userInfoService.lock(id,status);
        return  Result.ok();

    }

    @ApiOperation(value = "用户认证审核")
    @GetMapping("approval/{id}/{authStatus}")
    public Result approval(@PathVariable Long id,@PathVariable Integer authStatus){
        userInfoService.approval(id,authStatus );
        return Result.ok();
    }

    @ApiOperation(value = "用户详情")
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId){
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation(value = "用户列表（条件查询带分页）")
    @GetMapping("list/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> objectPage = new Page<>(page, limit);

        IPage<UserInfo> userInfoList = userInfoService.selectPage(objectPage,userInfoQueryVo);

        return Result.ok(userInfoList);
    }
}
